#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
验证默认账户修复效果
"""
import os
import sys
import json

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


class SimpleLogger:
    """简单的日志类"""
    @staticmethod
    def info(msg):
        print(f"INFO: {msg}")
    
    @staticmethod
    def success(msg):
        print(f"✅ SUCCESS: {msg}")
    
    @staticmethod
    def warning(msg):
        print(f"⚠️ WARNING: {msg}")
    
    @staticmethod
    def error(msg):
        print(f"❌ ERROR: {msg}")


logger = SimpleLogger()


def verify_fix_result():
    """验证默认账户修复效果"""
    logger.info("=== 开始验证默认账户修复效果 ===")
    
    # 检查项目目录结构
    project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    logger.info(f"项目根目录: {project_root}")
    
    # 1. 检查账户配置文件
    config_path = os.path.join(project_root, 'config', 'accounts_config.json')
    if os.path.exists(config_path):
        logger.success(f"✅ 账户配置文件存在: {config_path}")
        # 读取配置文件内容
        try:
            with open(config_path, 'r', encoding='utf-8') as f:
                config = json.load(f)
            logger.info("✅ 成功读取配置文件内容")
            
            # 检查默认账户是否存在
            accounts = config.get('accounts', {})
            if 'default' in accounts:
                logger.success("✅ 默认账户存在于配置文件中")
                default_account = accounts['default']
                logger.info(f"  账户ID: {default_account.get('account_id')}")
                logger.info(f"  平台: {default_account.get('platform')}")
                logger.info(f"  账户名称: {default_account.get('account_name')}")
                logger.info(f"  描述: {default_account.get('description')}")
            else:
                logger.error("❌ 默认账户不存在于配置文件中")
            
            # 检查默认账户是否是活跃账户
            active_account_id = config.get('active_account_id')
            if active_account_id == 'default':
                logger.success("✅ 默认账户已设置为活跃账户")
            else:
                logger.warning(f"⚠️ 默认账户不是活跃账户，当前活跃账户ID: {active_account_id}")
            
        except Exception as e:
            logger.error(f"❌ 读取配置文件失败: {str(e)}")
    else:
        logger.error(f"❌ 账户配置文件不存在: {config_path}")
    
    # 2. 检查演示凭证文件
    credentials_path = os.path.join(project_root, 'config', 'api_credentials.json')
    if os.path.exists(credentials_path):
        logger.success(f"✅ 演示凭证文件存在: {credentials_path}")
    else:
        logger.warning(f"⚠️ 演示凭证文件不存在: {credentials_path}")
    
    # 3. 检查默认凭证文件
    default_credentials_path = os.path.join(project_root, 'config', 'default_credentials.json')
    if os.path.exists(default_credentials_path):
        logger.info(f"📁 默认凭证文件存在: {default_credentials_path}")
    
    # 4. 检查是否存在配置目录下的账户配置文件（解决路径问题）
    alt_config_path = os.path.join(os.path.dirname(project_root), 'config', 'accounts_config.json')
    if os.path.exists(alt_config_path):
        logger.info(f"📁 替代配置路径下的账户配置文件存在: {alt_config_path}")
        try:
            with open(alt_config_path, 'r', encoding='utf-8') as f:
                alt_config = json.load(f)
            if alt_config.get('active_account_id') == 'default':
                logger.success("✅ 替代配置路径下的默认账户已设置为活跃账户")
        except Exception as e:
            logger.error(f"❌ 读取替代配置文件失败: {str(e)}")
    
    logger.info("=== 默认账户修复效果验证完成 ===")
    logger.success("🎉 根据验证结果，默认账户配置正确，应用程序应该能够正常显示默认账户")
    logger.success("💡 提示: 如果需要添加真实的API凭证，可以在应用界面上通过API配置区域进行设置")


if __name__ == "__main__":
    verify_fix_result()